package com.tedu.basic.Test;

import java.util.Arrays;
import java.util.Random;

//冒泡排序
public class Test_Array_Bubble {
    public static void main(String[] args) {
        int[] a={1,2,5,4,3};

        int[] b=f1(a);
        System.out.println("==============");
        System.out.println(Arrays.toString(b));

    }
    public static int[] f1(int[] a){

        for (int i = 1; i <=a.length-1; i++) {
            boolean flag=false;
            System.out.println("第"+i+"轮");
            for (int j = 0; j<=a.length-1-i; j++) {
                if(a[j]>a[j+1]){
                    int t = a[j];
                    a[j] = a[j+1];
                    a[j+1] = t;
                    flag = true;
                }
            }
            if (flag==false) {
                return a;
            }
                System.out.println(Arrays.toString(a));
            }

        return a;
    }
    public static int[] f2(){
        int[] a=new int[5];
        for (int i = 0; i <a.length ; i++) {
            a[i]=new Random().nextInt(100);
        }
        return a;

    }

}
